var mTeacherEvaltionPie = echarts.init(document.getElementById('teacherEvaltionPie'));
var mTeacherEvaltionBar = echarts.init(document.getElementById('teacherEvaltionBar'));
var mTeacherEvaltionPieRate = echarts.init(document.getElementById('teacherEvaltionPieRate'));
var mTeacherEvaltionRateBar = echarts.init(document.getElementById('teacherEvaltionRateBar'));
var mTeacherAttendancePie = echarts.init(document.getElementById('teacherAttendancePie'));
var mTeacherEvaltionTimeLine = echarts.init(document.getElementById('teacherEvaltionTimeLine'));

var setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "menuId",
            pIdKey: "parentId",
            rootPId: -1
        },
        key: {
            url:"nourl"
        }
    }
};
var ztree;
var teacherEvaltionPie  = {
    title : {
        text: '优良差占比',
        x:'center'
    },
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: ['优','良','差']
    },
    series : [
        {
            name: '占比',
            type: 'pie',
            // radius : '55%',
            // center: ['50%', '60%'],
            data:[
                {value:335, name:'优'},
                {value:310, name:'良'},
                {value:234, name:'差'}
            ],
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};
var teacherEvaltionBar = {
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    legend: {
        data: ['优','良','差']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    yAxis : [
        {
            type : 'category',
            data: ['教学态度','教学效果','教学内容','教学环节'],
        }
    ],
    xAxis : [
        {
            type : 'value'
        }
    ],
    series : [
        {
            name:'优',
            type:'bar',
            data:[2.0, 4.9, 7.0, 23.2]
        },
        {
            name:'良',
            type:'bar',
            data:[2.6, 5.9, 9.0, 26.4]
        },
        {
            name:'差',
            type:'bar',
            data:[2.0, 2.2, 3.3, 4.5]
        }
    ]
};
var teacherEvaltionPieRate  = {
    title : {
        text: '教学内容相符率',
        x:'center'
    },
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: ['相符','不相符']
    },
    series : [
        {
            name: '占比',
            type: 'pie',
            // radius : '55%',
            // center: ['50%', '60%'],
            data:[
                {value:335, name:'优'},
                {value:310, name:'良'},
                {value:234, name:'差'}
            ],
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};
var teacherEvaltionRateBar = {
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    legend: {
        data: ['相符','不相符']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis : [
        {
            type : 'category',
            data: ['语文','数学','英语','体育'],
        }
    ],
    yAxis : [
        {
            type : 'value'
        }
    ],
    series : [
        {
            name:'相符',
            type:'bar',
            stack: '相符率',
            barWidth:30,
            data:[2.0, 4.9, 7.0, 23.2]
        },
        {
            name:'不相符',
            type:'bar',
            stack: '相符率',
            barWidth:30,
            data:[2.6, 5.9, 9.0, 26.4]
        }
    ]
};
var teacherAttendancePie  = {
    title : {
        text: '出勤情况',
        x:'center'
    },
    tooltip : {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: ['正常','迟到','早退','调整']
    },
    series : [
        {
            name: '占比',
            type: 'pie',
            // radius : '55%',
            // center: ['50%', '60%'],
            data:[
                {value:335, name:'正常'},
                {value:335, name:'迟到'},
                {value:310, name:'早退'},
                {value:234, name:'调整'}
            ],
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]
};
var teacherEvaltionTimeLine = {
    title : {
        text: '授课时长纵向比',
        x:'center'
    },
    xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
        type: 'value',
        axisLabel: {
            formatter: '{value} 分钟'
        }
    },
    series: [{
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line',
        smooth: true
    }]
};


$(function () {
        vm.getTeacher();
    $.ajax({
        url: baseURL + "/TeacherInfo/getTeacherByCollege",
        data: {},
        success: function (r) {
            $("#teacher").append("<option value=''>请选择</option>");
            for (i = 0; i < r.list.length; i++) {
                var tname = r.list[i].name;
                var tid = r.list[i].id;
                $("#teacher").append("<option value='" + tid + "'>" + tname + "</option>");
            }
        }
    });
    }
);

function genData(count) {
    var nameList = [
        '赵', '钱', '孙', '李', '周', '吴', '郑', '王', '冯', '陈', '褚', '卫', '蒋', '沈', '韩', '杨', '朱', '秦', '尤', '许', '何', '吕', '施', '张', '孔', '曹', '严', '华', '金', '魏', '陶', '姜', '戚', '谢', '邹', '喻', '柏', '水', '窦', '章', '云', '苏', '潘', '葛', '奚', '范', '彭', '郎', '鲁', '韦', '昌', '马', '苗', '凤', '花', '方', '俞', '任', '袁', '柳', '酆', '鲍', '史', '唐', '费', '廉', '岑', '薛', '雷', '贺', '倪', '汤', '滕', '殷', '罗', '毕', '郝', '邬', '安', '常', '乐', '于', '时', '傅', '皮', '卞', '齐', '康', '伍', '余', '元', '卜', '顾', '孟', '平', '黄', '和', '穆', '萧', '尹', '姚', '邵', '湛', '汪', '祁', '毛', '禹', '狄', '米', '贝', '明', '臧', '计', '伏', '成', '戴', '谈', '宋', '茅', '庞', '熊', '纪', '舒', '屈', '项', '祝', '董', '梁', '杜', '阮', '蓝', '闵', '席', '季', '麻', '强', '贾', '路', '娄', '危'
    ];
    var legendData = [];
    var seriesData = [];
    var selected = {};
    for (var i = 0; i < 50; i++) {
        name = Math.random() > 0.65
            ? makeWord(4, 1) + '·' + makeWord(3, 0)
            : makeWord(2, 1);
        legendData.push(name);
        seriesData.push({
            name: name,
            value: Math.round(Math.random() * 100000)
        });
        selected[name] = i < 6;
    }

    return {
        legendData: legendData,
        seriesData: seriesData,
        selected: selected
    };

    function makeWord(max, min) {
        var nameLen = Math.ceil(Math.random() * max + min);
        var name = [];
        for (var i = 0; i < nameLen; i++) {
            name.push(nameList[Math.round(Math.random() * nameList.length - 1)]);
        }
        return name.join('');
    }
}

function setDate(id) {
    var Nowdate=new Date();
    M=Number(Nowdate.getMonth())+1;
    var today=Nowdate.getFullYear()+"-"+fix(M)+"-"+fix(Nowdate.getDate());
    if(id=='1'){
        $("#startDate").val(today);
        $("#endDate").val(today);
    }else if(id=='2'){
        $("#startDate").val(showWeekFirstDay());
        $("#endDate").val(today);
    }if(id=='3'){
        $("#startDate").val(showMonthFirstDay());
        $("#endDate").val(today);
    }
    query()
}
function showWeekFirstDay()
{
    var Nowdate=new Date();
    var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
    M=Number(WeekFirstDay.getMonth())+1
    return WeekFirstDay.getFullYear()+"-"+fix(M)+"-"+fix(WeekFirstDay.getDate());
}
function showWeekLastDay()
{
    var Nowdate=new Date();
    var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
    var WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000);
    M=Number(WeekLastDay.getMonth())+1
    return WeekLastDay.getFullYear()+"-"+M+"-"+WeekLastDay.getDate();
}
function showMonthFirstDay()
{
    var Nowdate=new Date();
    var MonthFirstDay=new Date(Nowdate.getFullYear(),Nowdate.getMonth(),1);
    M=Number(MonthFirstDay.getMonth())+1
    return MonthFirstDay.getFullYear()+"-"+fix(M)+"-"+fix(MonthFirstDay.getDate());
}
function fix(num){
    if(num<10)
        return "0"+num;
    else return ""+num;
}
function showMonthLastDay()
{
    var Nowdate=new Date();
    var MonthNextFirstDay=new Date(Nowdate.getFullYear(),Nowdate.getMonth()+1,1);
    var MonthLastDay=new Date(MonthNextFirstDay-86400000);
    M=Number(MonthLastDay.getMonth())+1
    return MonthLastDay.getFullYear()+"-"+M+"-"+MonthLastDay.getDate();
}
var vm = new Vue({
    el:'#rrapp',
    data:{
        showList: true,
        title: null,
        teacher:{
            id:null,
            name:null
        },
        menu:{
            parentName:null,
            parentId:0,
            type:1,
            orderNum:0
        }
    },
    methods: {
        query:function () {
            $.ajax({
                url: baseURL + "TeacherPortrait/getTeacherEvaltionEcharts",
                data: {
                    "teacherId":$("#teacher").val(),
                    "startDate":$("#startDate").val(),
                    "endDate":$("#endDate").val()
                },
                success: function (r) {
                    teacherEvaltionPie.series[0].data=r.dataPie;
                    teacherEvaltionBar.series=r.dataBar;
                    teacherEvaltionPieRate.series[0].data=r.dataRate;
                    teacherEvaltionTimeLine.xAxis.data=r.timeLine.xData;
                    teacherEvaltionTimeLine.series[0].data=r.timeLine.seriesData;
                    teacherAttendancePie.series[0].data=r.teacherAttendancePie;
                    mTeacherEvaltionPie.setOption(teacherEvaltionPie);
                    mTeacherEvaltionBar.setOption(teacherEvaltionBar);
                    mTeacherEvaltionPieRate.setOption(teacherEvaltionPieRate);
                    mTeacherEvaltionRateBar.setOption(teacherEvaltionRateBar);
                    mTeacherAttendancePie.setOption(teacherAttendancePie);
                    mTeacherEvaltionTimeLine.setOption(teacherEvaltionTimeLine);
                }
            });
        },
        getTeacher: function(){
            //加载菜单树
            $.get(baseURL + "TeacherPortrait/getTeacherTree", function(r){
                ztree = $.fn.zTree.init($("#teacherTree"), setting, r.list);
                var node = ztree.getNodeByParam("menuId", vm.menu.parentId);
                ztree.selectNode(node);
            })
            vm.imgUrl='';
        },
        teacherTree: function(){
            layer.open({
                type: 1,
                offset: '50px',
                skin: 'layui-layer-molv',
                title: "选择老师",
                area: ['300px', '450px'],
                shade: 0,
                shadeClose: false,
                content: jQuery("#menuLayer"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var node = ztree.getSelectedNodes();
                    //选择上级菜单
                    vm.teacher.id = node[0].menuId;
                    vm.teacher.name = node[0].name;

                    layer.close(index);
                }
            });
        }
    }
});